package com.example.yjhero.safeapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.yjhero.safeapp.R;
import com.example.yjhero.safeapp.entities.ContactInfo;
import java.util.List;

public class ContactAdapter extends BaseAdapter {

    private List<ContactInfo> contactInfos;
    private Context mContext;

    public ContactAdapter(List<ContactInfo> contactInfos, Context mContext) {
        this.contactInfos = contactInfos;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return contactInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return contactInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null) {

            convertView = View.inflate(mContext, R.layout.item_list_contact_select,null);
            holder=new ViewHolder();
            holder.mNameTV=convertView.findViewById(R.id.tv_name);
            holder.mPhoneTV=convertView.findViewById(R.id.tv_phone);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mNameTV.setText(contactInfos.get(position).getName());
        holder.mPhoneTV.setText(contactInfos.get(position).getPhone());
        return convertView;
    }


    static class ViewHolder {
        TextView mNameTV;
        TextView mPhoneTV;
    }

}
